// 统一风格样式
import getWidgetListFlat from '@/libs/edit/getWidgetListFlat'
export default function useBaseStyle(styles) {
    // 设置控件统一样式
    const onSetWidgetBaseStyle = widget => {
        switch (widget.eles.type) {
            case 'button':
                widget.eles.style['background-color'] = styles.button
                break;
            case 'title-ele':
                widget.eles.customFeature.markColor = styles['title-ele']
                break;
            case 'breakline':
                widget.eles.style['border-bottom-color'] = styles.breakline
                break;
        }
        return widget
    }

    // 设置页面统一样式
    const onSetPageBaseStyle = pageData => {
        pageData.customFeature.titleColor = styles.navigationBarTextStyle
        pageData.customFeature.titleBackgroundColor = styles.navigationBarBackgroundColor
        const widgetListFlat = getWidgetListFlat(pageData.eles)
        Object.values(widgetListFlat).forEach(widget => {
            if (widget.widgetData.eles.type === 'custom-top-nav') {
                widget.widgetData.eles.customFeature.style.color = styles.navigationBarTextStyle
                widget.widgetData.eles.customFeature.style['background-color'] = styles.navigationBarBackgroundColor
            } else {
                onSetWidgetBaseStyle(widget.widgetData)
            }
        })
    }

    return {
        onSetWidgetBaseStyle,
        onSetPageBaseStyle
    }
}